﻿//提交元素
function fromSubmit() {
    $("#btnOK").attr("disabled", "disabled");
    if (validator() == true) {
        var mydata = { userid: $("#userID").val(), age: $("#UserAge").val(), phonenumber: $("#UserphoneNumber").val(), Sex: $("#userSex").val(), departmentID: $("#userDepartmentName").val(), Address: $("#UserAddress").val() };
        $.post(
               "/Userinfo/AjaxUpdateUserinfo",
               { userid: mydata.userid, age: mydata.age, phonenumber: mydata.phonenumber, sex: mydata.Sex, departmentID: mydata.departmentID, address: mydata.Address },
               function(date) {
                   alert(date);
                   $("#btnOK").attr("disabled", "");
               })
    }
    else {
        alert("对不起！信息验证没有通过。请看具体的错误信息！");
        $("#btnOK").attr("disabled", "");
    }
}
//验证页面元素
function validator() {
    //验证年龄
    var intege1 = /^[0-9]{1,2}$/;
    var user_age = $("#UserAge").val();
    if (intege1.test(user_age) != true) {
        $("#UserAgeTip").text("您输入的年龄格式不合法！");
        return false;
    }
    if (user_age * 1 <= 1 * 0 || user_age * 1 > 1 * 90) {
        $("#UserAgeTip").text("年龄已经超出范围！");
        return false;
    }
    $("#UserAgeTip").text("");

    //验证电话
    var user_phoneNumber = $("#UserphoneNumber").val();
    var mobile = /^(13|15)[0-9]{9}$/;
    if (mobile.test(user_phoneNumber) != true) {
        $("#UserphoneNumberTip").text("您输入的号码格式不合法！");
        return false;
    }
    $("#UserphoneNumberTip").text("");

    //验证性别
    var user_sex = $("#userSex").val();
    if (user_sex == "0") {
        $("#userSexTip").text("性别必须选择！");
        return false;
    }
    $("#userSexTip").text("");

    //验证部门名称
    var user_departmentname = $("#userDepartmentName").val();
    if (user_departmentname == "0") {
        $("#userDepartmentNameTip").text("部门必须选择！");
        return false;
    }
    $("#userDepartmentNameTip").text("");

    //验证地址
    var user_address = $("#UserAddress").val();
    if (user_address == "") {
        $("#UserAddressTip").text("您输入的地址格式不合法！");
        return false;
    }
    $("#UserAddressTip").text("");
    return true;
}

function BindCategory() {
    var count = document.forms['from1']['userDepartmentName'].options.length;
    for (var i = 1; i < count; i++) {
        if ($("#userDepartmentName").get(0).options[i].value == $("#userdepartmentID").val()) {
            $("#userDepartmentName").get(0).options[i].selected = true;
        }
    }
}